import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:flutter/material.dart';
import 'package:tetap_ad_batch/common/styles/colorsVariable.dart';
import 'package:tetap_ad_batch/router/router.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:window_manager/window_manager.dart';

class App extends StatelessWidget {
  final AdaptiveThemeMode? savedThemeMode;

  const App({super.key, this.savedThemeMode});

  @override
  Widget build(BuildContext context) {
    return AdaptiveTheme(
      light: _lightTheme(),
      dark: _darkTheme(),
      initial: savedThemeMode ?? AdaptiveThemeMode.dark,
      debugShowFloatingThemeButton: true,
      builder: (theme, darkTheme) => DragToResizeArea(
        child: MaterialApp.router(
          title: "Tetap客户端",
          routerConfig: RouterUtils.routes,
          debugShowCheckedModeBanner: false,
          theme: theme,
          darkTheme: darkTheme,
          builder: EasyLoading.init(),
        ),
      ),
    );
  }

  ThemeData _lightTheme() {
    final colorScheme = Colorsvariable.getColorScheme(Brightness.light);
    return ThemeData(
      brightness: Brightness.light,
      useMaterial3: true,
      fontFamily: 'AlibabaPuHuiTi',
      // colorScheme: colorScheme,
      textTheme: TextTheme(
        bodyMedium:
            TextStyle(color: colorScheme.colors.textPrimary, fontSize: 16),
        labelMedium:
            TextStyle(color: colorScheme.colors.inverTextPrimary, fontSize: 16),
      ),
      primaryColor: colorScheme.colorScheme.primary,
      splashColor: colorScheme.colorScheme.primary.withOpacity(0.2),
      // hoverColor: colorScheme.primary.withOpacity(0.06),
      highlightColor: colorScheme.colorScheme.primary.withOpacity(0.08),
      hintColor: colorScheme.colorScheme.primary.withOpacity(0.6),
      inputDecorationTheme: InputDecorationTheme(
        labelStyle: TextStyle(color: colorScheme.colors.textPrimary),
        enabledBorder: OutlineInputBorder(
          borderRadius: Colorsvariable.radiusMedium,
          borderSide:
              BorderSide(width: 1, color: colorScheme.colors.borderColor),
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: Colorsvariable.radiusMedium,
          borderSide:
              BorderSide(width: 1, color: colorScheme.colorScheme.primary),
        ),
      ),
      checkboxTheme: CheckboxThemeData(
        checkColor:
            WidgetStateProperty.all(colorScheme.colors.inverTextPrimary),
      ),
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          backgroundColor: colorScheme.colorScheme.primary,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(Colorsvariable.middle),
          ),
          padding:
              const EdgeInsets.only(top: 18, bottom: 18, left: 12, right: 12),
        ),
      ),
    );
  }

  ThemeData _darkTheme() {
    final colorScheme = Colorsvariable.getColorScheme(Brightness.dark);

    return ThemeData(
      brightness: Brightness.dark,
      useMaterial3: true,
      fontFamily: 'AlibabaPuHuiTi',
      // colorScheme: colorScheme,
      textTheme: TextTheme(
        bodyMedium:
            TextStyle(color: colorScheme.colors.textPrimary, fontSize: 16),
        labelMedium:
            TextStyle(color: colorScheme.colors.textPrimary, fontSize: 16),
      ),
      primaryColor: colorScheme.colorScheme.primary,
      splashColor: colorScheme.colorScheme.primary.withOpacity(0.2),
      // hoverColor: colorScheme.primary.withOpacity(0.06),
      highlightColor: colorScheme.colorScheme.primary.withOpacity(0.08),
      hintColor: colorScheme.colorScheme.primary.withOpacity(0.6),
      inputDecorationTheme: InputDecorationTheme(
        labelStyle: TextStyle(color: colorScheme.colors.textPrimary),
        enabledBorder: OutlineInputBorder(
          borderRadius: Colorsvariable.radiusMedium,
          borderSide:
              BorderSide(width: 1, color: colorScheme.colors.borderColor),
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: Colorsvariable.radiusMedium,
          borderSide:
              BorderSide(width: 1, color: colorScheme.colorScheme.primary),
        ),
      ),
      checkboxTheme: CheckboxThemeData(
        checkColor: WidgetStateProperty.all(colorScheme.colors.textPrimary),
      ),
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          backgroundColor: colorScheme.colorScheme.primary,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(Colorsvariable.middle),
          ),
          padding:
              const EdgeInsets.only(top: 18, bottom: 18, left: 12, right: 12),
        ),
      ),
    );
  }
}
